export default defineEventHandler(async (event) => {
  // 模拟文章数据
  const posts = [
    {
      id: 1,
      title: 'Nuxt3 入门指南：从零开始构建现代化应用',
      content: 'Nuxt3是一个基于Vue3的全栈框架，提供了开箱即用的功能...',
      excerpt: '本文详细介绍Nuxt3的核心特性和使用方法，帮助你快速上手这个强大的框架。',
      author: {
        id: 1,
        name: '张三',
        avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=1'
      },
      category: '技术教程',
      tags: ['Nuxt3', 'Vue3', '前端开发'],
      status: 'published',
      viewCount: 1250,
      likeCount: 89,
      commentCount: 23,
      coverImage: 'https://picsum.photos/800/400?random=1',
      createdAt: '2024-03-01T10:00:00Z',
      updatedAt: '2024-03-15T14:30:00Z'
    },
    {
      id: 2,
      title: 'TypeScript 高级技巧：提升代码质量',
      content: 'TypeScript作为JavaScript的超集，提供了强大的类型系统...',
      excerpt: '分享一些TypeScript的高级用法和最佳实践，让你的代码更加健壮。',
      author: {
        id: 2,
        name: '李四',
        avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=2'
      },
      category: '编程技巧',
      tags: ['TypeScript', 'JavaScript', '编程'],
      status: 'published',
      viewCount: 890,
      likeCount: 67,
      commentCount: 15,
      coverImage: 'https://picsum.photos/800/400?random=2',
      createdAt: '2024-03-05T15:20:00Z',
      updatedAt: '2024-03-12T09:15:00Z'
    },
    {
      id: 3,
      title: '现代CSS布局技术详解',
      content: 'CSS Grid和Flexbox是现代CSS布局的两大核心技术...',
      excerpt: '深入探讨CSS Grid和Flexbox的使用方法，掌握现代布局技术。',
      author: {
        id: 3,
        name: '王五',
        avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=3'
      },
      category: '前端开发',
      tags: ['CSS', 'Grid', 'Flexbox', '布局'],
      status: 'published',
      viewCount: 756,
      likeCount: 45,
      commentCount: 12,
      coverImage: 'https://picsum.photos/800/400?random=3',
      createdAt: '2024-03-08T11:45:00Z',
      updatedAt: '2024-03-10T16:20:00Z'
    },
    {
      id: 4,
      title: 'Vue3 Composition API 最佳实践',
      content: 'Composition API是Vue3中最重要的新特性之一...',
      excerpt: '详细介绍Composition API的使用方法和最佳实践。',
      author: {
        id: 1,
        name: '张三',
        avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=1'
      },
      category: 'Vue开发',
      tags: ['Vue3', 'Composition API', '前端开发'],
      status: 'draft',
      viewCount: 0,
      likeCount: 0,
      commentCount: 0,
      coverImage: 'https://picsum.photos/800/400?random=4',
      createdAt: '2024-03-12T08:30:00Z',
      updatedAt: '2024-03-12T08:30:00Z'
    },
    {
      id: 5,
      title: 'Node.js 性能优化指南',
      content: '在高并发场景下，Node.js的性能优化变得尤为重要...',
      excerpt: '分享Node.js应用性能优化的实用技巧和工具。',
      author: {
        id: 2,
        name: '李四',
        avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=2'
      },
      category: '后端开发',
      tags: ['Node.js', '性能优化', '后端'],
      status: 'published',
      viewCount: 634,
      likeCount: 38,
      commentCount: 8,
      coverImage: 'https://picsum.photos/800/400?random=5',
      createdAt: '2024-03-14T13:15:00Z',
      updatedAt: '2024-03-15T10:45:00Z'
    }
  ]

  // 获取查询参数
  const query = getQuery(event)
  const page = parseInt(query.page as string) || 1
  const limit = parseInt(query.limit as string) || 10
  const category = query.category as string
  const status = query.status as string
  const search = query.search as string

  // 过滤数据
  let filteredPosts = posts
  if (category) {
    filteredPosts = filteredPosts.filter(post => post.category === category)
  }
  if (status) {
    filteredPosts = filteredPosts.filter(post => post.status === status)
  }
  if (search) {
    filteredPosts = filteredPosts.filter(post => 
      post.title.toLowerCase().includes(search.toLowerCase()) ||
      post.excerpt.toLowerCase().includes(search.toLowerCase())
    )
  }

  // 分页
  const startIndex = (page - 1) * limit
  const endIndex = startIndex + limit
  const paginatedPosts = filteredPosts.slice(startIndex, endIndex)

  // 模拟延迟
  await new Promise(resolve => setTimeout(resolve, 300))

  return {
    code: 200,
    message: '获取文章列表成功',
    data: {
      posts: paginatedPosts,
      pagination: {
        page,
        limit,
        total: filteredPosts.length,
        totalPages: Math.ceil(filteredPosts.length / limit)
      }
    }
  }
}) 